import 'dart:io';

import 'package:simulator/core/simulator.dart';
import 'package:simulator/utils/log.dart';
import 'package:simulator/utils/options.dart';
import 'package:simulator/utils/utils.dart';

void main(List<String> args) async {
  int status;
  int time = 0;
  Options.getInstance().parserAndValidate(args);
  LogPrint.logInfo('start simulator with args:$args \n args parser ok');
  Simulator simulator = Simulator.getInstance();
  await simulator.init();
  while ((status = (await simulator.mainLoopShouldExit())) == 0) {
    simulator.mcu.interruptHandle();
    time += simulator.mcu.exec();

    ///需要放弃CPU的执行,让其它协程有执行机会
    await Future.delayed(Duration.zero);
  }
  Utils.getInstance().exitHook();
  LogPrint.logInfo('exit simulator with time:$time');
  exit(status);
}
